<script setup lang="ts">
import { ref } from 'vue'
import KnowledgeCard from './KnowledgeCard.vue'

const list = ref<KnowledgeList>([])
const loading = ref(false)
const finished = ref(false)
// 定义props
import type { KnowledgeType, KnowledgeList } from '../../../types/consult'

import { getKnowledgePage } from '../../../services/consult'
const props = defineProps<{
  // 属性名：类型
  type: KnowledgeType
}>()

const params = ref({
  type: props.type,
  current: 1,
  pageSize: 10
})
const onLoad = async () => {
  const res = await getKnowledgePage(params.value)
  list.value.push(...res.data.rows)
  if (params.value.current >= res.data.pageTotal) {
    finished.value = true
  } else {
    params.value.current++
  }
  loading.value = false
}
</script>

<template>
  <div class="knowledge-list">
    {{ type }}
    <van-list @load="onLoad" :finished="finished" finished-text="没有更多了" v-model:loading="loading">
      <knowledge-card v-for="item in list" :key="item.id" :item="item"></knowledge-card>
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.knowledge-list {
  padding: 0 15px;
}
</style>
